// axios.defaults.headers.post['Content-Type'] = 'application/json;';
var vm = new Vue({
    el: '.main',
    data: {
        uname: '',
        upas: '',
        reupas:'',
        isActivity: true,
        isActivity_s: false,
        status:"student"
    },
    methods: {
        handle() {
            this.isActivity = !this.isActivity,
                this.isActivity_s = !this.isActivity_s
        },
        goLogin(even) {
            even.preventDefault();
            this.handle()
        },
        onSubmit_login() {

            const data = JSON.stringify({ uname: vm.uname, upas: vm.upas })
            console.log(status);
            if (this.status == "student") {
                axios.post('http://127.0.0.1:8000/api/login', `${data}`).then(function (res) {
                    console.log(res);
    
                    if (res.data.status !== 0) {
                        return alert(res.data.message)
                    }
                    localStorage.setItem('token', res.data.token)
                    // 跳转到后台主页
                    location.href = './student/student_index.html'
    
                });
            } else {
                axios.post('http://127.0.0.1:8000/api/login_teacher', `${data}`).then(function (res) {
                    console.log(res);
    
                    if (res.data.status !== 0) {
                        return alert(res.data.message)
                    }
                    console.log(res);
                    localStorage.setItem('token', res.data.token)
                    // 跳转到后台主页

                    location.href = './teacher/teacher_index.html'
                })
            }
            return false;
        },
        onSubmit_reg() {
            if (this.upas !== this.reupas) {
                return alert('两次密码不一致')
            }
            const data = JSON.stringify({ uname: vm.uname, upas: vm.upas })
            axios.post('http://127.0.0.1:8000/api/reguser', `${data}`).then(function (res) {
                console.log(res);
            });
            return false;
        }
    }
});